<template>
  <div class="box">
    <div class="title">
      <span class="el-icon-arrow-left"
            @click="$router.go(-1)"></span>
      {{ $t('home.Myspendingrecord') }}
    </div>
    <!-- 查询 -->
    <div class="consume_input">
      <input @focus="searchFocus"
             @focusout="searchFocusOut"
             v-model="searchForm.keyword"
             @change="index"
             class="iconfont"
             :placeholder="showSearchIcon?'\ue630' + $t('home.Search'):''"/>
    </div>
    <!-- 记录 -->
    <div v-show="dataList.length>0" class="centent">
      <div v-for="(item,index) in dataList" :key="index">
        <div class="title_card">
          <div>{{ $t('支出') }}: ${{ item.payout }} {{ $t('收入') }}: ${{ item.income }}</div>
          <div class="title_card_back">
            <el-date-picker
              @change="searchYearMonth"
              v-model="item.yearmonth"
              type="month"
              :placeholder="$t('Month')">
            </el-date-picker>
          </div>
        </div>
        <div class="card_back"
             @click="$router.push({path:'/listConsumptionDetail',query:{id:info.id}})"
             v-for="(info,subIndex) in item.data" :key="subIndex">
          <div>
            <img src="../../../../assets/static/Consumption/q1.png" alt="">
            <div>
              <div>{{ info.remark }}</div>
              <!--              <div>{{ info.create_time }}</div>-->
              <div>{{ checkTime(info.create_time) }}</div>
            </div>
          </div>
          <div>
            <!--            <span>{{ info.type }}</span>-->
            <span>{{ Number(info.money) }}</span>
          </div>
        </div>
      </div>
    </div>
    <div v-show="dataList.length===0" class="title_card title-select">
      <div class="title_card_back">
        <el-date-picker
          @change="searchYearMonth"
          v-model="yearMonth"
          type="month"
          :placeholder="$t('Month')">
        </el-date-picker>
      </div>
    </div>
    <div v-show="dataList.length===0" class="centent col-wrapper" style="height: 75vh;justify-content: center">
      <div class="height_flex">
        <div class="height_flex_img">
          <img src="../../../../assets/static/activities/box.png" alt="">
          <div class="height_flex_size">{{ $t('还没有任何消费记录！') }}</div>
          <div>{{ $t('Ways to add funds to your balance') }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {index} from '@/api/merbership/recharge'
import '@/styles/height_flex.scss'
import '@/styles/flax.css'

export default {
  data() {
    return {
      icon: '\ue630 搜索',
      showSearchIcon: true,
      dataList: [],
      remark: '',
      yearMonth: '',
      searchForm: {
        yearmonth: undefined,
        keyword: undefined
      }
    }
  },
  activated() {
    this.index()
  },
  methods: {
    /**
     * 按月份查找
     * @param val
     */
    searchYearMonth(val) {
      this.searchForm.yearmonth = String(val.getFullYear()) + '-' + String(val.getMonth() + 1)
      this.index()
    },
    /**
     * 搜索框失去焦点时
     */
    searchFocusOut() {
      this.showSearchIcon = true
    },
    /**
     * 搜索框获取焦点时
     */
    searchFocus() {
      this.showSearchIcon = false
    },
    /**
     * 时间戳判断
     * @param timeStamp
     * @returns {string}
     */
    checkTime(timeStamp) {
      return new Date(Number(timeStamp * 1000)).toLocaleString()
    },
    // -------------- axios -----------------
    /**
     * 我的消费记录
     */
    index() {
      index(this.$qs.stringify(this.searchForm))
        .then(res => {
          if (res.data.code === 1) {
            this.dataList = res.data.data
          } else {
            this.$message.error(res.data.msg)
          }
        })
    }
  }
}
</script>

<style scoped>
.title-select {
  margin: 15px;
}

.box {
  background-color: #F5F5F5;
}

/* 标题 */
.title {
  background-color: #7ac91b;
  color: #fff;
  font-size: 18px;
  text-align: center;
  padding: 15px;
  font-weight: bold;
}

.title .el-icon-arrow-left {
  float: left;
  margin-top: 5px;
}

/*  */
.consume_input {
  margin: 15px;
}

.consume_input input {
  box-shadow: 0 0 5px #ccc;
  width: 98%;
  text-align: center;
  outline: none;
  border: none;
  height: 40px;
  border-radius: 10px;
}

.consume_input input::-webkit-input-placeholder {
  color: #67C41D;
}

/*  */
.centent {
  margin: 15px;
}

/* 标题卡 */
.title_card {
  background-color: rgba(193, 225, 169, 0.5);
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #64BE1D;
  border-radius: 10px;
}

.title_card_back {
  width: 120px;
  overflow: hidden;
  background-color: #fff;
  /*padding: 8px;*/
  border-radius: 8px;
}

.title_card_back .el-icon-arrow-down {
  margin-left: 3px;
}

/*  */
.card_back {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  margin: 10px 0;
  padding: 10px;
  border-radius: 10px;
  color: #63BD1F;
  font-size: 18px;
  font-weight: bold;
}

.card_back img {
  width: 45px;
  margin-right: 10px;
  margin-top: 5px;
}

.card_back > div:nth-child(1) {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: #999999;
  font-weight: normal;
}

.card_back > div:nth-child(1) > div > div:nth-child(1) {
  margin-bottom: 3px;
  font-size: 13px;
  font-weight: bold;
  color: #333333;
}
</style>
